
# =====================================
# solve error：UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
# =====================================
import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030') #改变标准输出的默认编码

import requests

url = 'https://www.zhihu.com/hot'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36',
    # plan A
    'cookie':'_zap=1292f7b5-fc3c-4ca9-9fde-535185b6aaed; d_c0="AABduzszwxGPTr_NxilUxapDTP2QQPidTdg=|1597937435"; _ga=GA1.2.1772810783.1597937436; __snaker__id=3kMKHx7KYDEjnFef; _9755xjdesxxd_=32; YD00517437729195%3AWM_TID=CtRVWqTTlUdAFFFQUBI7wLxBwS4nZRzC; _xsrf=2i6UeDwXf3oVg554HXF5UHpbJXkfi5Cb; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1618674668,1618717253,1618751162,1618752017; SESSIONID=UwQerdSEYkEge4gijyJVgpTCQJoSttDNOzwMGm3HRPP; JOID=VFsTAkzwRoukgsNGHfcCFVa-94EMoDTdx_GiEF-oKMvE4fYkceR29sOGw0QcaSZM0IUZi6-UOTMohuEX1ZCSIsI=; osd=VlkTB07yRIuhgMFEHfIAF1S-8oMOojTYxfOgEFqqKsnE5PQmc-Rz9MGEw0EeayRM1Ycbia-ROzEqhuQV15KSJ8A=; tst=h; tshl=; captcha_session_v2="2|1:0|10:1618759140|18:captcha_session_v2|88:MW9NUVVxTU5qeFVZS2FKUlFJL1k3ejJlcDNzemZHZlNSRHlyUDViY001aXVlTmxFTkxveXdTenJEVzBkaHRZNg==|85d527b585685bd46e6bcd93ea66d38c319d0ac48eb9115781d0485642a05503"; gdxidpyhxdE=cv60OgTZLqeDf4i9RcNU1Y4L9%2Bstc2C9%2FhvaKYj9cJ%2Bh2Ptbprob%5Ce3YRrEO7%2FeXx%2FfPoCutqVqa73968MeT16JTkmlHYUWjI4dTY%2Fz3ozUAjVlNTD11OuEocSexxxzm3z2L%5CXDGeNAkJPTQPRH2%2FVH%2FVHrsSAW%5CGJo0xfdcy8Ragt3c%3A1618760039229; YD00517437729195%3AWM_NI=JUH8I0Clvso8V24D96isUH8hKUkNotdom%2BIzL6oBIfmhBl5slYO%2B3siDf8wvE2BpKjxl3HU5uj01Jy7faxNRn%2Btf0vN1ofmF9LJo1nSLsoARtBT%2FUW5IPa%2FQNcysA96KWmQ%3D; YD00517437729195%3AWM_NIKE=9ca17ae2e6ffcda170e2e6eea4aa658da9b985d634b3928ba6d45a839b9e84aa64a6a9a2d2fb5ab0b4a7a4e82af0fea7c3b92a8a8b88d9cc3c81b4ba94ee3496eefca5bc3eabad9ba9bb64898ba5afee80a8b1a3cccc7290eaa1a3cc6eafb88e8db879b08781ccb279ab9caad9f67e87ee8e91ca62bcb4fda9d83fb7b600d2c973f5baaf99cd5aaef5bc87b37e8eefa187f04efb948690b4669194bd90c45ab89e9cd0d85df797a082ae5b8ebdb794c433f695998ed437e2a3; captcha_ticket_v2="2|1:0|10:1618759157|17:captcha_ticket_v2|704:eyJ2YWxpZGF0ZSI6IkNOMzFfZGVxMnNzWS5jZV9zZU9FbHlLWDA0cl85TWNZTF9EUi1VOTYuSEFGa2hUbXJHRkJldE94X09iZVpFLnZfZDBqZTdSdk1LelctYkJucGtkVjRNWkU1RE05TzAtOEhUOEd1cVo3eWVRMS1Cckd4XzVMbTdFdWJQYzh2RWpCQ0hFSVMwaXZFV1MwT05HS0RnMVhuZ0h0Ny1GaFF0Nnl3cGJIVEVBLWhCTm1Kd1BMSUFEcGFpVU45REFrR3NMVDRwS3BUSmdwRGM4V0FQbDY2aTdSb3J3SUxFWk9JMXRRLkpTaVA5LkI2R083QVE4UFZlRDl2RVBVYXhMSk03bFNwQm5yWmI1ZncxSEhza09oRW9mLTl3U2FCS2ZENmo4V2tUeHcxTnYyLUVMV0VNdkQ5X0lWRjllZlU2X0F4bVJITFZ1d1dhSXJDbDQ3V3hWcHBQdkJkT2k4cDZmZkU5eTZybHQ4dzZuY3Y4YTFnWWQ0bTFONl9VbmNXbGhYNXVHa0xMS3hkRzhNV1Q5Ulo2cGZoNGNENEpqa3hYZUJkSUc3dFV1YlZfVFdNQ2R1NWhZNGMwckdadzgwdmRvNVRLZlQ4NGg0b1ZwSHE5dEZlMWRPMGJuWi1reklxRlZSTm9wb05PQ3lrS0x2VmU5Uk9uNl9EbV9pOUVqeDZRSEFSbmZjMyJ9|05306f2ef8f49a503005e2835bedb5a126244c78251762925b93217ddf4ab516"; z_c0="2|1:0|10:1618759158|4:z_c0|92:Mi4xYm9wNEFnQUFBQUFBQUYyN096UERFU1lBQUFCZ0FsVk45cHRwWVFENFZpT1E0OGs5QUZJTUVNUHpZaTc3VDRsQUdR|ff090738658c86309ba2aefa4e9ba96c76ac4e2c681cec2b70b9ca95d37f1c0b"; Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49=1618759157; KLBRSID=c450def82e5863a200934bb67541d696|1618760131|1618759133'
}
resp = requests.get(url, headers=headers)
print(resp.content.decode('utf-8'))
#print(resp.cookies)
#print(resp.cookies.get_dict())